package com.briup.jz.web.controller;

import com.briup.jz.bean.Category;
import com.briup.jz.bean.Privilege;
import com.briup.jz.bean.extend.CategoryExtend;
import com.briup.jz.service.ICategoryService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @program: jz
 * @description: 栏目控制器
 * @author: catmilko
 * @create: 2020-06-11 16:41
 **/

@RestController
@RequestMapping("category")
@Api(description = "分类管理接口")
public class CategoryController {
    @Autowired
    private ICategoryService categoryService;

    @ApiOperation(value = "查询所有分类信息")
    @GetMapping("findAll")
    public Message findAll(){
        List<Category> list = categoryService.findAll();
        return MessageUtil.success(list);
    }

    @ApiOperation(value = "通过id查询分类信息")
    @ApiImplicitParam(name = "id", value = "类别唯一编号", required = true, paramType = "query")
    @GetMapping("findById")
    public Message findById(long id) {
        Category category = categoryService.findById(id);
        return MessageUtil.success(category);
    }

    @ApiOperation(value = "保存或更新分类信息")
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(Category category){
        categoryService.saveOrUpdate(category);
        return MessageUtil.success("保存或者更新成功");
    }

    @ApiOperation(value = "通过id删除栏目信息")
    @GetMapping("deleteById")
    public Message deleteById(long id){
        categoryService.deleteById(id);
        return MessageUtil.success("删除成功");
    }

    @ApiOperation(value = "查询分类树")
    @GetMapping("findAllWithChild")
    public Message findAllWithChild(){
        List<CategoryExtend> list = categoryService.findAllWithChild();
        return MessageUtil.success(list);
    }
}















